﻿using System;

namespace CardPlay.Model.CardModel
{
    public sealed class CardFaceSpecification
    {
        public Rank? Rank
        {
            get;
            set;
        }
        
        public Suit? Suit
        {
            get;
            set;
        }
        
        public SuitColor? SuitColor
        {
            get;
            set;
        }

        public bool IsSatisfiedBy(CardFace cardFace)
        {
            return  
                (Rank == null || Rank == cardFace.Rank) &&
                (Suit == null || Suit == cardFace.Suit) &&
                (SuitColor == null || SuitColor == cardFace.Suit.Color());
        }

        public static CardFaceSpecification Any
        {
            get { return new CardFaceSpecification(); }
        }

        public static implicit operator Predicate<CardFace>(CardFaceSpecification specification)
        {
            return specification.IsSatisfiedBy;
        }
    }
}
